<template>
	<view class="mains box box-tb">
		<u-navbar :is-back="false" :is-fixed="true" title="五育通·劳动教育云" v-if="current == 0 || current ==1"
			:background="background" :border-bottom="false" title-color="#fff">
			<view class="slot-wrap">
				<view class="ml20" style="color: #fff;text-align: center;">
				</view>
			</view>
		</u-navbar>
		<u-navbar :is-back="false" title="我的" title-color="#fff" v-if="current == 2" :background="background" :border-bottom="false"></u-navbar>
		<view class="content">
			<view class="w100" style="height: 100%;" v-show="current == 0 || current ==1">
				<course-view ref="cousView" style="height: 100%;"></course-view>
			</view>
			<view class="w100" v-show="current == 2" style="height: 100%;">
				<person-view ref="personViews" style="height: 100%;"></person-view>
			</view>
		</view>
		<u-tabbar v-model="current" :list="list" @change="goIndex" active-color="#4A8CF5" inactive-color="#646D7E" :midButton="true"
			 bg-color="#f1f1fd">
		</u-tabbar>
	</view>
</template>

<script>
	import courseView from './compoents/index/courseView.vue';//首页
	import personView from './compoents/person/person.vue';//我的
	export default {
		components: {
			courseView,
			personView
		},
		data() {
			return {
				user: uni.getStorageSync("user"),
				list: [{
						text: '首页',
						// pagePath: '/pages/home/home',
						iconPath: "/static/tabBar/home.png",
						selectedIconPath: "/static/tabBar/home_act.png",
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '',
						// pagePath: '/pages/task/task',
						customIcon: true,
						color: "#4A8CF5",
						selectedColor: "#4A8CF5",
						customIcon: true,
						midButton: true
					},
					{
						iconPath: "/static/tabBar/my.png",
						selectedIconPath: "/static/tabBar/my_act.png",
						text: '我的',
						// pagePath: '/pages/my/my',
						customIcon: false,
						color: "#646D7E",
						selectedColor: "#4A8CF5"
					}
				],
				current: 0,
				background: {
					backgroundColor: '#7484f7'
				},
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.cousView.setData();
		},
		onShareAppMessage(res) {
			return {
				title:uni.getStorageSync('fxTitle'),
				path: '/pages/index/share?data=' + encodeURIComponent(JSON.stringify(uni.getStorageSync('chat_info'))),
				imageUrl: uni.getStorageSync('fxImage')
			}
		},
		onShow() {
			//console.log(this.current);
			// this.$refs.cousView.setdata();
			// if(this.current == 0 ){
			// 	this.$nextTick(res=>{
			// 		this.$refs.cousView.setdata();
			// 	})
			// }
			// else if(this.current == 1){
			// 	this.$refs.cousView.setdata();
			// }
			// else {
			// 	this.$refs.personViews.setdata()
			// }
			if (this.current == 2) {
				this.$refs.personViews.setdata()
			}
		},
		onLoad() {
			this.$nextTick(()=>{
				if(this.current ==0){
					this.$refs.cousView.setdata();
				}
				if(this.current == 1){
					this.$refs.cousView.setdata();
				}
				if (this.current == 2) {
					this.$refs.personViews.setdata()
				}
			})
			
		},
		onPageScroll(res) {
			this.background.backgroundColor = '#7484f7'
			if (res.scrollTop >= 50) {
				this.background.backgroundColor = '#7484f7'
			} else {
				this.background.backgroundColor = '#7484f7'
			}
		},
		onReachBottom(e) {
			// if (this.current == 0 || this.current == 1) {
				this.$refs.cousView.fenye();
				this.$refs.cousView.regfenye();
			// }
		},
		methods: {
			goIndex(i) {
				//console.log(i);
				if (i == 0) {
					uni.setNavigationBarTitle({title: '首页'});
				} else if (i== 2) {
					uni.setNavigationBarTitle({title: '我的'});
				}else{
					uni.navigateTo({
						url: "/pageHome/pubClassStyle"
					})
				}
			},
			handleCancel() {
				this.show = false
			},
			pubTask(index) {
				if (index == 0) {
					uni.navigateTo({url: "/pageHome/pubClassStyle"})
				} else if (index == 1) {
					uni.navigateTo({url: "/pageHome/pubCouseTask"})
				} else {
					uni.navigateTo({url: "/pageHome/pubSjTask"})
				}
				this.show = false
			}

		}
	}
</script>

<style scoped lang="scss">
	.mains {
		width: 100%;
		height: 100%;
	}

	.content {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		/* color: #8f8f94; */
	}

	.bar {
		margin-top: -20rpx;
		display: flex;
		align-items: center;
		padding-left: 50rpx;
	}

	.ml50 {
		margin-left: 20rpx;
	}

	.flex-1 {
		flex: 1;
		text-align: center;
		height: 112rpx;
		line-height: 112rpx;
		font-size: 28rpx;
		background: #F8F9FC;
		color: #1C1C1C;
		font-weight: bold;
	}

	.pubbar {
		width: 100%;
		padding: 100rpx;
	}

	.title-top {
		padding-left: 76rpx;
		width: 100%;
		text-align: left;
		font-size: 28rpx;
		height: 128rpx;
		line-height: 128rpx;
		border-bottom: 2rpx solid #EEF4F8;
		color: #959AA5;
	}
</style>